home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl70b2.lha / tcl7.0b2 / tests / open.test < prev    next >
Text File  |  1993-06-03  |  22KB  |  652 lines

  1. # Commands covered:  open, close, gets, puts, read, seek, tell, eof, flush
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27. # $Header: /user6/ouster/tcl/tests/RCS/open.test,v 1.18 93/06/03 10:30:24 ouster Exp $ (Berkeley)
  28.  
  29. if {[string compare test [info procs test]] == 1} then {source defs}
  30.  
  31. catch {exec rm -f test1 test2 test3}
  32. exec cat > test1 << "Two lines: this one\nand this one\n"
  33. exec cat > test2 << "line1\nline2\nline3\nline4\nline5\n"
  34.  
  35. test open-1.1 {open command (files only)} {
  36.     set f [open test1]
  37.     set x [gets $f]
  38.     close $f
  39.     set x
  40. } {Two lines: this one}
  41. test open-1.2 {open command (files only)} {
  42.     set f [open test1]
  43.     set f2 [open test2]
  44.     set f3 [open test1]
  45.     set f4 [open test1]
  46.     set x [list [gets $f] [gets $f2] [gets $f3] [gets $f4] \
  47.         [gets $f] [gets $f2]]
  48.     close $f
  49.     close $f2
  50.     close $f3
  51.     close $f4
  52.     set x
  53. } {{Two lines: this one} line1 {Two lines: this one} {Two lines: this one} {and this one} line2}
  54. test open-1.3 {open command (files only)} {
  55.     set f [open test3 w]
  56.     puts $f xyz
  57.     close $f
  58.     exec cat test3
  59. } "xyz"
  60. test open-1.4 {open command (files only)} {
  61.     set f [open test3 w]
  62.     puts $f xyz
  63.     close $f
  64.     set f [open test3 a]
  65.     puts $f 123
  66.     close $f
  67.     exec cat test3
  68. } "xyz\n123"
  69. test open-1.5 {open command (files only)} {
  70.     set f [open test3 w]
  71.     puts $f xyz\n123
  72.     close $f
  73.     set f [open test3 r+]
  74.     set x [gets $f]
  75.     seek $f 0 current
  76.     puts $f 456
  77.     close $f
  78.     list $x [exec cat test3]
  79. } "xyz {xyz
  80. 456}"
  81. test open-1.6 {open command (files only)} {
  82.     set f [open test3 w]
  83.     puts $f xyz\n123
  84.     close $f
  85.     set f [open test3 w+]
  86.     puts $f xyzzy
  87.     seek $f 2
  88.     set x [gets $f]
  89.     close $f
  90.     list $x [exec cat test3]
  91. } "zzy xyzzy"
  92. test open-1.7 {open command (files only)} {
  93.     set f [open test3 w]
  94.     puts $f xyz\n123
  95.     close $f
  96.     set f [open test3 a+]
  97.     puts $f xyzzy
  98.     flush $f
  99.     set x [tell $f]
  100.     seek $f -4 cur
  101.     set y [gets $f]
  102.     close $f
  103.     list $x [exec cat test3] $y
  104. } {14 {xyz
  105. 123
  106. xyzzy} zzy}
  107.  
  108. test open-2.1 {errors in open command} {
  109.     list [catch {open} msg] $msg
  110. } {1 {wrong # args: should be "open filename ?access? ?permissions?"}}
  111. test open-2.2 {errors in open command} {
  112.     list [catch {open a b c d} msg] $msg
  113. } {1 {wrong # args: should be "open filename ?access? ?permissions?"}}
  114. test open-2.3 {errors in open command} {
  115.     list [catch {open test1 x} msg] $msg
  116. } {1 {illegal access mode "x"}}
  117. test open-2.4 {errors in open command} {
  118.     list [catch {open test1 rw} msg] $msg
  119. } {1 {illegal access mode "rw"}}
  120. test open-2.5 {errors in open command} {
  121.     list [catch {open test1 r+1} msg] $msg
  122. } {1 {illegal access mode "r+1"}}
  123. test open-2.6 {errors in open command} {
  124.     string tolower [list [catch {open _non_existent_} msg] $msg $errorCode]
  125. } {1 {couldn't open "_non_existent_": no such file or directory} {posix enoent {no such file or directory}}}
  126.  
  127. if {![file exists ~/_test_] && [file writable ~]} {
  128.     test open-3.1 {tilde substitution in open} {
  129.     set f [open ~/_test_ w]
  130.     puts $f "Some text"
  131.     close $f
  132.     set x [file exists $env(HOME)/_test_]
  133.     exec rm -f $env(HOME)/_test_
  134.     set x
  135.     } 1
  136. }
  137. test open-3.2 {tilde substitution in open} {
  138.     set home $env(HOME)
  139.     unset env(HOME)
  140.     set x [list [catch {open ~/foo} msg] $msg]
  141.     set env(HOME) $home
  142.     set x
  143. } {1 {couldn't find HOME environment variable to expand "~/foo"}}
  144.  
  145. test open-4.1 {file id parsing errors} {
  146.     list [catch {eof gorp} msg] $msg $errorCode
  147. } {1 {bad file identifier "gorp"} NONE}
  148. test open-4.2 {file id parsing errors} {
  149.     list [catch {eof filex} msg] $msg
  150. } {1 {bad file identifier "filex"}}
  151. test open-4.3 {file id parsing errors} {
  152.     list [catch {eof file12a} msg] $msg
  153. } {1 {bad file identifier "file12a"}}
  154. test open-4.4 {file id parsing errors} {
  155.     list [catch {eof file123} msg] $msg
  156. } {1 {file "file123" isn't open}}
  157. test open-4.5 {file id parsing errors} {
  158.     list [catch {eof file1} msg] $msg
  159. } {0 0}
  160. test open-4.5 {file id parsing errors} {
  161.     list [catch {eof stdin} msg] $msg
  162. } {0 0}
  163. test open-4.6 {file id parsing errors} {
  164.     list [catch {eof stdout} msg] $msg
  165. } {0 0}
  166. test open-4.7 {file id parsing errors} {
  167.     list [catch {eof stderr} msg] $msg
  168. } {0 0}
  169. test open-4.8 {file id parsing errors} {
  170.     list [catch {eof stderr1} msg] $msg
  171. } {1 {bad file identifier "stderr1"}}
  172. set f [open test1]
  173. close $f
  174. set expect "1 {file \"$f\" isn't open}"
  175. test open-4.9 {file id parsing errors} {
  176.     list [catch {eof $f} msg] $msg
  177. } $expect
  178.  
  179. test open-5.1 {close command (files only)} {
  180.     list [catch {close} msg] $msg $errorCode
  181. } {1 {wrong # args: should be "close fileId"} NONE}
  182. test open-5.2 {close command (files only)} {
  183.     list [catch {close a b} msg] $msg $errorCode
  184. } {1 {wrong # args: should be "close fileId"} NONE}
  185. test open-5.3 {close command (files only)} {
  186.     list [catch {close gorp} msg] $msg $errorCode
  187. } {1 {bad file identifier "gorp"} NONE}
  188. test open-5.4 {close command (files only)} {
  189.     list [catch {close file4} msg] \
  190.         [string range $msg [string first {" } $msg] end] $errorCode
  191. } {1 {" isn't open} NONE}
  192.  
  193. test open-6.1 {puts command} {
  194.     list [catch {puts} msg] $msg $errorCode
  195. } {1 {wrong # args: should be "puts" ?-nonewline? ?fileId? string} NONE}
  196. test open-6.2 {puts command} {
  197.     list [catch {puts a b c d} msg] $msg $errorCode
  198. } {1 {wrong # args: should be "puts" ?-nonewline? ?fileId? string} NONE}
  199. test open-6.3 {puts command} {
  200.     list [catch {puts a b nonewlinx} msg] $msg $errorCode
  201. } {1 {bad argument "nonewlinx": should be "nonewline"} NONE}
  202. test open-6.4 {puts command} {
  203.     list [catch {puts gorp "New text"} msg] $msg $errorCode
  204. } {1 {bad file identifier "gorp"} NONE}
  205. test open-6.5 {puts command} {
  206.     set f [open test3]
  207.     set x [list [catch {puts $f "New text"} msg] \
  208.     [string range $msg [string first " " $msg] end] $errorCode]
  209.     close $f
  210.     set x
  211. } {1 { wasn't opened for writing} NONE}
  212. test open-6.6 {puts command} {
  213.     set f [open test3 w]
  214.     puts -nonewline $f "Text1"
  215.     puts -nonewline $f " Text 2"
  216.     puts $f " Text 3"
  217.     close $f
  218.     exec cat test3
  219. } {Text1 Text 2 Text 3}
  220.  
  221. test open-7.1 {gets command} {
  222.     list [catch {gets} msg] $msg $errorCode
  223. } {1 {wrong # args: should be "gets fileId ?varName?"} NONE}
  224. test open-7.2 {gets command} {
  225.     list [catch {gets a b c} msg] $msg $errorCode
  226. } {1 {wrong # args: should be "gets fileId ?varName?"} NONE}
  227. test open-7.3 {gets command} {
  228.     list [catch {gets a} msg] $msg $errorCode
  229. } {1 {bad file identifier "a"} NONE}
  230. test open-7.4 {gets command} {
  231.     set f [open test3 w]
  232.     set x [list [catch {gets $f} msg] \
  233.         [string range $msg [string first " " $msg] end] $errorCode]
  234.     close $f
  235.     set x
  236. } {1 { wasn't opened for reading} NONE}
  237. set f [open test3 w]
  238. puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  239. puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  240. puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  241. puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  242. puts $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  243. close $f
  244. test open-7.5 {gets command with long line} {
  245.     set f [open test3]
  246.     set x [gets $f]
  247.     close $f
  248.     set x
  249. } {abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ}
  250. test open-7.6 {gets command with long line} {
  251.     set f [open test3]
  252.     set x [gets $f y]
  253.     close $f
  254.     list $x $y
  255. } {260 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ}
  256. test open-7.7 {gets command and end of file} {
  257.     set f [open test3 w]
  258.     puts -nonewline $f "Test1\nTest2"
  259.     close $f
  260.     set f [open test3]
  261.     set x {}
  262.     set y {}
  263.     lappend x [gets $f y] $y
  264.     set y {}
  265.     lappend x [gets $f y] $y
  266.     set y {}
  267.     lappend x [gets $f y] $y
  268.     close $f
  269.     set x
  270. } {5 Test1 5 Test2 -1 {}}
  271. set f [open test3 w]
  272. puts $f "Line 1"
  273. puts $f "Line 2"
  274. close $f
  275. test open-7.8 {gets command and bad variable} {
  276.     catch {unset x}
  277.     set x 24
  278.     set f [open test3 r]
  279.     set result [list [catch {gets $f x(0)} msg] $msg]
  280.     close $f
  281.     set result
  282. } {1 {can't set "x(0)": variable isn't array}}
  283.  
  284. test open-8.1 {read command} {
  285.     list [catch {read} msg] $msg $errorCode
  286. } {1 {wrong # args: should be "read fileId ?numBytes?" or "read ?-nonewline? fileId"} NONE}
  287. test open-8.2 {read command} {
  288.     list [catch {read -nonewline} msg] $msg $errorCode
  289. } {1 {bad file identifier "-nonewline"} NONE}
  290. test open-8.3 {read command} {
  291.     list [catch {read a b c} msg] $msg $errorCode
  292. } {1 {wrong # args: should be "read fileId ?numBytes?" or "read ?-nonewline? fileId"} NONE}
  293. test open-8.4 {read command} {
  294.     list [catch {read -nonew file4} msg] $msg $errorCode
  295. } {1 {bad file identifier "-nonew"} NONE}
  296. test open-8.5 {read command} {
  297.     list [catch {read stdin foo} msg] $msg $errorCode
  298. } {1 {bad argument "foo": should be "nonewline"} NONE}
  299. test open-8.6 {read command} {
  300.     list [catch {read file10} msg] $msg $errorCode
  301. } {1 {file "file10" isn't open} NONE}
  302. test open-8.7 {read command} {
  303.     set f [open test3 w]
  304.     set x [list [catch {read $f} msg] \
  305.         [string range $msg [string first " " $msg] end] $errorCode]
  306.     close $f
  307.     set x
  308. } {1 { wasn't opened for reading} NONE}
  309. test open-8.8 {read command} {
  310.     set f [open test1]
  311.     set x [list [catch {read $f 12z} msg] $msg $errorCode]
  312.     close $f
  313.     set x
  314. } {1 {expected integer but got "12z"} NONE}
  315. test open-898 {read command} {
  316.     set f [open test1]
  317.     set x [list [catch {read $f z} msg] $msg $errorCode]
  318.     close $f
  319.     set x
  320. } {1 {bad argument "z": should be "nonewline"} NONE}
  321. test open-8.10 {read command} {
  322.     set f [open test1]
  323.     set x [list [read $f 1] [read $f 2] [read $f]]
  324.     close $f
  325.     set x
  326. } {T wo { lines: this one
  327. and this one
  328. }}
  329. test open-8.11 {read command, with over-large count} {
  330.     set f [open test1]
  331.     set x [read $f 100]
  332.     close $f
  333.     set x
  334. } {Two lines: this one
  335. and this one
  336. }
  337. test open-8.12 {read command, -nonewline switch} {
  338.     set f [open test1]
  339.     set x [read -nonewline $f]
  340.     close $f
  341.     set x
  342. } {Two lines: this one
  343. and this one}
  344.  
  345. test open-9.1 {seek command} {
  346.     list [catch {seek foo} msg] $msg $errorCode
  347. } {1 {wrong # args: should be "seek fileId offset ?origin?"} NONE}
  348. test open-9.2 {seek command} {
  349.     list [catch {seek foo a b c} msg] $msg $errorCode
  350. } {1 {wrong # args: should be "seek fileId offset ?origin?"} NONE}
  351. test open-9.3 {seek command} {
  352.     list [catch {seek foo 0} msg] $msg $errorCode
  353. } {1 {bad file identifier "foo"} NONE}
  354. test open-9.4 {seek command} {
  355.     set f [open test2]
  356.     set x [list [catch {seek $f xyz} msg] $msg $errorCode]
  357.     close $f
  358.     set x
  359. } {1 {expected integer but got "xyz"} NONE}
  360. test open-9.5 {seek command} {
  361.     set f [open test2]
  362.     set x [list [catch {seek $f 100 gorp} msg] $msg $errorCode]
  363.     close $f
  364.     set x
  365. } {1 {bad origin "gorp": should be start, current, or end} NONE}
  366. set f [open test3 w]
  367. puts -nonewline $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  368. close $f
  369. test open-9.6 {seek command} {
  370.     set f [open test3]
  371.     set x [read $f 1]
  372.     seek $f 3
  373.     lappend x [read $f 1]
  374.     seek $f 0 start
  375.     lappend x [read $f 1]
  376.     seek $f 10 current
  377.     lappend x [read $f 1]
  378.     seek $f -2 end
  379.     lappend x [read $f 1]
  380.     seek $f 50 end
  381.     lappend x [read $f 1]
  382.     seek $f 1
  383.     lappend x [read $f 1]
  384.     close $f
  385.     set x
  386. } {a d a l Y {} b}
  387.  
  388. test open-10.1 {tell command} {
  389.     list [catch {tell} msg] $msg $errorCode
  390. } {1 {wrong # args: should be "tell fileId"} NONE}
  391. test open-10.2 {tell command} {
  392.     list [catch {tell a b} msg] $msg $errorCode
  393. } {1 {wrong # args: should be "tell fileId"} NONE}
  394. test open-10.3 {tell command} {
  395.     list [catch {tell a} msg] $msg $errorCode
  396. } {1 {bad file identifier "a"} NONE}
  397. test open-10.4 {tell command} {
  398.     set f [open test2]
  399.     set x [tell $f]
  400.     read $f 3
  401.     lappend x [tell $f]
  402.     seek $f 2
  403.     lappend x [tell $f]
  404.     seek $f 10 current
  405.     lappend x [tell $f]
  406.     seek $f 0 end
  407.     lappend x [tell $f]
  408.     close $f
  409.     set x
  410. } {0 3 2 12 30}
  411.  
  412. test open-11.1 {eof command} {
  413.     list [catch {eof} msg] $msg $errorCode
  414. } {1 {wrong # args: should be "eof fileId"} NONE}
  415. test open-11.2 {eof command} {
  416.     list [catch {eof a b} msg] $msg $errorCode
  417. } {1 {wrong # args: should be "eof fileId"} NONE}
  418. test open-11.3 {eof command} {
  419.     list [catch {eof file100} msg] $msg $errorCode
  420. } {1 {file "file100" isn't open} NONE}
  421. test open-11.4 {eof command} {
  422.     set f [open test1]
  423.     set x [eof $f]
  424.     lappend x [eof $f]
  425.     gets $f
  426.     lappend x [eof $f]
  427.     gets $f
  428.     lappend x [eof $f]
  429.     gets $f
  430.     lappend x [eof $f]
  431.     lappend x [eof $f]
  432.     close $f
  433.     set x
  434. } {0 0 0 0 1 1}
  435.  
  436. test open-12.1 {flush command} {
  437.     list [catch {flush} msg] $msg $errorCode
  438. } {1 {wrong # args: should be "flush fileId"} NONE}
  439. test open-12.2 {flush command} {
  440.     list [catch {flush a b} msg] $msg $errorCode
  441. } {1 {wrong # args: should be "flush fileId"} NONE}
  442. test open-12.3 {flush command} {
  443.     list [catch {flush a} msg] $msg $errorCode
  444. } {1 {bad file identifier "a"} NONE}
  445. test open-12.4 {flush command} {
  446.     set f [open test3]
  447.     set x [list [catch {flush $f} msg] \
  448.         [string range $msg [string first " " $msg] end] $errorCode]
  449.     close $f
  450.     set x
  451. } {1 { wasn't opened for writing} NONE}
  452. test open-12.5 {flush command} {
  453.     set f [open test3 w]
  454.     puts $f "Line 1"
  455.     puts $f "Line 2"
  456.     set f2 [open test3]
  457.     set x {}
  458.     lappend x [read -nonewline $f2]
  459.     close $f2
  460.     flush $f
  461.     set f2 [open test3]
  462.     lappend x [read -nonewline $f2]
  463.     close $f2
  464.     close $f
  465.     set x
  466. } {{} {Line 1
  467. Line 2}}
  468.  
  469. test open-13.1 {I/O to command pipelines} {
  470.     list [catch {open "| cat < test1 > test3" w} msg] $msg $errorCode
  471. } {1 {can't write input to command: standard input was redirected} NONE}
  472. test open-13.2 {I/O to command pipelines} {
  473.     list [catch {open "| echo > test3" r} msg] $msg $errorCode
  474. } {1 {can't read output from command: standard output was redirected} NONE}
  475. test open-13.3 {I/O to command pipelines} {
  476.     list [catch {open "| echo > test3" r+} msg] $msg $errorCode
  477. } {1 {can't read output from command: standard output was redirected} NONE}
  478. test open-13.4 {writing to command pipelines} {
  479.     exec rm test3
  480.     set f [open "| cat | cat > test3" w]
  481.     puts $f "Line 1"
  482.     puts $f "Line 2"
  483.     close $f
  484.     exec cat test3
  485. } {Line 1
  486. Line 2}
  487. test open-13.5 {reading from command pipelines} {
  488.     set f [open "| cat test2" r]
  489.     set x [list [gets $f] [gets $f] [gets $f]]
  490.     close $f
  491.     set x
  492. } {line1 line2 line3}
  493. test open-13.6 {both reading and writing from/to command pipelines} {
  494.     set f [open "| cat -u" r+]
  495.     puts $f "Line1"
  496.     flush $f
  497.     set x [gets $f]
  498.     close $f
  499.     set x
  500. } {Line1}
  501. test open-13.7 {errors in command pipelines} {
  502.     set f [open "|gorp"]
  503.     list [catch {close $f} msg] $msg [lindex $errorCode 0] [lindex $errorCode 2]
  504. } {1 {couldn't find "gorp" to execute} CHILDSTATUS 1}
  505. test open-13.8 {errors in command pipelines} {
  506.     set f [open "|gorp" w]
  507.     exec sleep 1
  508.     puts $f output
  509.     set x [list [catch {flush $f} msg] [concat \
  510.         [string range $msg 0 [string first {"} $msg]] \
  511.         [string range $msg [string first : $msg] end]] $errorCode]
  512.     catch {close $f}
  513.     string tolower $x
  514. } {1 {error flushing " : broken pipe} {posix epipe {broken pipe}}}
  515. test open-13.9 {errors in command pipelines} {
  516.     set f [open "|gorp" w]
  517.     list [catch {close $f} msg] $msg \
  518.         [lindex $errorCode 0] [lindex $errorCode 2]
  519. } {1 {couldn't find "gorp" to execute} CHILDSTATUS 1}
  520. test open-13.10 {errors in command pipelines} {
  521.     set f [open "|gorp" w]
  522.     exec sleep 1
  523.     puts $f output
  524.     string tolower [list [catch {close $f} msg] [concat \
  525.         [string range $msg 0 [string first {"} $msg]] \
  526.         [string range $msg [string first : $msg] end]] \
  527.         [lindex $errorCode 0] [lindex $errorCode 2]]
  528. } {1 {error closing " : broken pipe
  529. couldn't find "gorp" to execute} childstatus 1}
  530.  
  531. test open-14.1 {POSIX open access modes: RDONLY} {
  532.     set f [open test1 RDONLY]
  533.     set x [list [gets $f] [catch {puts $f Test} msg] $msg]
  534.     close $f
  535.     set x
  536. } {{Two lines: this one} 1 {"file3" wasn't opened for writing}}
  537. test open-14.2 {POSIX open access modes: RDONLY} {
  538.     catch {exec rm -f test3}
  539.     string tolower [list [catch {open test3 RDONLY} msg] $msg]
  540. } {1 {couldn't open "test3": no such file or directory}}
  541. test open-14.3 {POSIX open access modes: WRONLY} {
  542.     catch {exec rm -f test3}
  543.     string tolower [list [catch {open test3 WRONLY} msg] $msg]
  544. } {1 {couldn't open "test3": no such file or directory}}
  545. test open-14.4 {POSIX open access modes: WRONLY} {
  546.     exec echo xyzzy > test3
  547.     set f [open test3 WRONLY]
  548.     puts -nonewline $f "ab"
  549.     seek $f 0 current
  550.     set x [list [catch {gets $f} msg] $msg]
  551.     close $f
  552.     lappend x [exec cat test3]
  553. } {1 {"file3" wasn't opened for reading} abzzy}
  554. test open-14.5 {POSIX open access modes: RDWR} {
  555.     catch {exec rm -f test3}
  556.     string tolower [list [catch {open test3 RDWR} msg] $msg]
  557. } {1 {couldn't open "test3": no such file or directory}}
  558. test open-14.6 {POSIX open access modes: RDWR} {
  559.     exec echo xyzzy > test3
  560.     set f [open test3 RDWR]
  561.     puts -nonewline $f "ab"
  562.     seek $f 0 current
  563.     set x [gets $f]
  564.     close $f
  565.     lappend x [exec cat test3]
  566. } {zzy abzzy}
  567. test open-14.7 {POSIX open access modes: CREAT} {
  568.     catch {exec rm -f test3}
  569.     set f [open test3 {WRONLY CREAT} 0600]
  570.     file stat test3 stats
  571.     set x [format "0%o" [expr $stats(mode)&0777]]
  572.     puts $f "line 1"
  573.     close $f
  574.     lappend x [exec cat test3]
  575. } {0600 {line 1}}
  576. if $atBerkeley {
  577.     test open-14.8 {POSIX open access modes: CREAT} {
  578.     catch {exec rm -f test3}
  579.     set f [open test3 {WRONLY CREAT}]
  580.     close $f
  581.     file stat test3 stats
  582.     format "0%o" [expr $stats(mode)&0777]
  583.     } 0664
  584. }
  585. test open-14.9 {POSIX open access modes: CREAT} {
  586.     exec echo xyzzy > test3
  587.     set f [open test3 {WRONLY CREAT}]
  588.     puts -nonewline $f "ab"
  589.     close $f
  590.     exec cat test3
  591. } abzzy
  592. test open-14.10 {POSIX open access modes: APPEND} {
  593.     exec echo xyzzy > test3
  594.     set f [open test3 {WRONLY APPEND}]
  595.     puts $f "new line"
  596.     seek $f 0
  597.     puts $f "abc"
  598.     close $f
  599.     exec cat test3
  600. } {xyzzy
  601. new line
  602. abc}
  603. test open-14.11 {POSIX open access modes: EXCL} {
  604.     exec echo xyzzy > test3
  605.     set msg [list [catch {open test3 {WRONLY CREAT EXCL}} msg] $msg]
  606.     regsub " already " $msg " " msg
  607.     string tolower $msg
  608. } {1 {couldn't open "test3": file exists}}
  609. test open-14.12 {POSIX open access modes: EXCL} {
  610.     catch {exec rm -f test3}
  611.     set x [catch {set f [open test3 {WRONLY CREAT EXCL}]}]
  612.     puts $f "A test line"
  613.     close $f
  614.     lappend x [exec cat test3]
  615. } {0 {A test line}}
  616. test open-14.13 {POSIX open access modes: TRUNC} {
  617.     exec echo xyzzy > test3
  618.     set f [open test3 {WRONLY TRUNC}]
  619.     puts $f abc
  620.     close $f
  621.     exec cat test3
  622. } {abc}
  623. if $atBerkeley {
  624.     test open-14.14 {POSIX open access modes: NOCTTY} {
  625.     catch {exec rm -f test3}
  626.     list [catch {open test3 {WRONLY NOCTTY CREAT}} msg] $msg
  627.     } {1 {access mode "NOCTTY" not supported by this system}}
  628.     test open-14.15 {POSIX open access modes: NONBLOCK} {
  629.     catch {exec rm -f test3}
  630.     set f [open test3 {WRONLY NONBLOCK CREAT}]
  631.     puts $f "NONBLOCK test"
  632.     close $f
  633.     exec cat test3
  634.     } {NONBLOCK test}
  635. }
  636. test open-14.16 {POSIX open access modes: errors} {
  637.     concat [catch {open test3 "FOO \{BAR BAZ"} msg] $msg\n$errorInfo
  638. } "1 unmatched open brace in list
  639. unmatched open brace in list
  640.     while processing open access modes \"FOO {BAR BAZ\"
  641.     invoked from within
  642. \"open test3 \"FOO \\{BAR BAZ\"\""
  643. test open-14.17 {POSIX open access modes: errors} {
  644.     list [catch {open test3 {FOO BAR BAZ}} msg] $msg
  645. } {1 {invalid access mode "FOO": must be RDONLY, WRONLY, RDWR, APPEND, CREAT EXCL, NOCTTY, NONBLOCK, or TRUNC}}
  646. test open-14.18 {POSIX open access modes: errors} {
  647.     list [catch {open test3 {TRUNC CREAT}} msg] $msg
  648. } {1 {access mode must include either RDONLY, WRONLY, or RDWR}}
  649.  
  650. catch {exec rm -f test1 test2 test3}
  651. concat {}
  652.